package com.cisetech.service.impl;


import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cisetech.mapper.bobocai.ActivityMapper;
import com.cisetech.service.ActivityService;
import com.cisetech.util.session.SystemRequestContext;
import com.cisetech.vo.Page;
import com.cisetech.vo.bobocai.LContent;
import com.cisetech.vo.bobocai.LUser;

@Service
public class ActivityServiceImpl implements ActivityService {
	static Logger logger = LoggerFactory.getLogger(ActivityServiceImpl.class); 
	@Autowired
	ActivityMapper activityMapper;

	@Override
	public String addActivity(LContent content) {
		try {
			//HttpSession s = SystemRequestContext.getSession();
			LUser user = SystemRequestContext.getUser();
			//LUser user = (LUser) s.getAttribute("luser");
			//LUser user = SystemRequestContext.getUser();
			if( user== null){
				return "2";//你一掉线请重新登录
			}
			content.setName(user.getName());
			activityMapper.addActivity(content);
			return "0";
		} catch (Exception e) {
			logger.debug(e.getMessage());
			return "1";
		}
	}
	//查询记录
	@Override
	public Page<LContent> findListActivity(LContent content) {
		Page<LContent> page = new Page<LContent>();
		if(content!=null && content.getPageNo()>0){
			content.setCalculationPge((content.getPageNo()-1)*content.getPageSize());
		}
		List<LContent> list = activityMapper.findListActivity(content);
		Integer i = activityMapper.findListCountActivity(content);
		page.Pagehtml(content.getPageNo(), content.getPageSize(), i, list);
		return page;//list==null ? new ArrayList<LContent>() : list;
	}
	//查询一共有多少条
	@Override
	public Integer findListCountActivity(LContent content) {
		Integer i = activityMapper.findListCountActivity(content);
		return i;
	}
}
